package interfaces1;

import java.util.Comparator;

class CompareX implements Comparator<Dog>{
	public int compare(Dog d1, Dog d2) {
		if (d1.getX() > d2.getX())
			return +1;
		if (d1.getX() < d2.getX())
			return -1;
		return 0;
	}
}

class CompareY implements Comparator<Dog>{
	public int compare(Dog d1, Dog d2) {
		if (d1.getY() > d2.getY())
			return +1;
		if (d1.getY() < d2.getY())
			return -1;
		return 0;
	}	
}

public class Comparing4 {

	public static void main(String[] args) {
		Dog a = new Dog( 4, 5.0 );
		Dog b = new Dog( 7, 3.2 );
		
		System.out.println(" a is " + a);
		System.out.println(" b is " + b);
		
		CompareX cx = new CompareX();
		System.out.println("Comparing x components:");
		System.out.println("  a and b: " + cx.compare(a,b));
		System.out.println("  b and a: " + cx.compare(b,a));
		System.out.println("  a and a: " + cx.compare(a,a));
		System.out.println("  b and b: " + cx.compare(b,b));

		CompareY cy = new CompareY();
		
		System.out.println("Comparing y components:");
		System.out.println("  a and b: " + cy.compare(a,b));
		System.out.println("  b and a: " + cy.compare(b,a));
		System.out.println("  a and a: " + cy.compare(a,a));
		System.out.println("  b and b: " + cy.compare(b,b));
	}
}
